package com.blog.common.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.lang3.StringUtils;

/**
 * 
 * @ClassName:layui  PageUtils
 * @author: chb
 * @date: 2018年7月27日 上午9:51:37
 * @作用：传入map  解析map    然后返回新的map集合中 
 */
public class LayuiPageUtils {

		public static Map<String,Object> PageMap(Map<String,Object> map)
		{
			if(map==null)
			{
				return map;
			}
			//map.containsKey("5")  判断是否存在key
			Integer pageNumber=Integer.parseInt((String)map.get("page"));//
			Integer pageSize=Integer.parseInt((String) map.get("limit"));//每页显示的条数
			
			Map<String,Object> newMap=new HashMap<String,Object>();
			for (Entry<String, Object> entry : map.entrySet()) {
				
				if("page".equals(entry.getKey()))
				{
					newMap.put("pageSize",pageSize);
					continue;
				}
				if("limit".equals(entry.getKey()))
				{
					newMap.put("pageNumber", (pageNumber-1)*pageSize);
					continue;
				}
				
				if("createTime".equals(entry.getKey()))
				{
					String time=(String)map.get("createTime");
					if(StringUtils.isNotEmpty(time))
					{
						String stateTime = time.substring(0,10);
						String endTime= time.substring(13,23);
						newMap.put("stateTime",stateTime+" 00:00:00");
						newMap.put("endTime",endTime+" 23:59:59");
					}
					 
					continue;
				}
				newMap.put(entry.getKey(),entry.getValue());
			}
			
			return newMap;
		}
		
		
		public static void main(String[] args) {
			
			Map<String,Object> newMap=new HashMap<String,Object>();
			newMap.put("aaa","2");
			Integer pageNumber=Integer.parseInt((String) newMap.get("aaa"));
		//	System.out.println(pageNumber);
			
			
			String ddd="2018-07-10 - 2018-08-23";
			String a = ddd.substring(0,10);
			String as = ddd.substring(13,23);
			//System.out.println(as);
			
			StringBuffer bf =new StringBuffer();
			bf.append("ARRIVE_DATE >= to_date('"+a.trim()+" 00:00:00','yyyy-mm-dd hh24:mi:ss') and \r\n");
			bf.append("ARRIVE_DATE <= to_date('"+as.trim()+" 23:59:59','yyyy-mm-dd hh24:mi:ss'))\r\n");
			
			System.out.println(bf.toString());
		}
}
